#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>

//const char *exe="otherExe";

int main()
{
	extern char **environ;
	putenv("PRIVATE_ENV=666666");
	pid_t id=fork();
	if(id==0)
	{
	//	char *const myargv[]={
	//		"ls",
	//		"-l",
	//		"-a",
	//		NULL
	//	};
		printf("before:I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
		//sleep(5);
		//这类方法的标准写法
		//execl("/usr/bin/ls","ls","-a","-l",NULL);
		//execl("/usr/bin/top","top",NULL);
		//execlp("ls","ls","-a","-l",NULL);
		//execv("/usr/bin/ls",myargv);
		//无论是可执行程序，还是脚本，为什么能跨语言调用？
		//因为所有语言调用起来，本质都是进程！！！
		char* const myargv[]={
			"otherExe",
			"-a",
			"-b",
			"-c",
			NULL
		};
		execle("./otherExe","otherExe","-a","-w","-v",NULL,environ);
		//execl("/usr/bin/bash","bash","test.sh",NULL);
		//execl("/usr/bin/python3","python3","test.py",NULL);
		printf("after:I am a process,pid:%d,ppid:%d\n",getpid(),getppid());
		exit(1);
	}
	pid_t ret=waitpid(id,NULL,0);
	if(ret>0)
	{
		printf("wait success,father pid:%d,ret id:%d\n",getpid(),ret);
	}
	sleep(5);
	return 0;
}
